//
//  WYCbankcardViewController.m
//  掌上还
//
//  Created by 王晓民 on 2018/3/7.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "WYCbankcardViewController.h"
#import "WYCmyCardCotroller.h"
#import "WYCbankViewController.h"
@interface WYCbankcardViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray *bankimgArr;
@property(nonatomic,strong)NSArray *banktitArr;
@property(nonatomic,strong)UILabel  *bankLb;
@property(nonatomic,strong)NSArray *bankstyleArr;

@end

@implementation WYCbankcardViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupNav];
    _bankimgArr = @[@"bank_circle_zhaoshang",@"bank_circle_pinan",@"bank_circle_pufa",@"bank_circle_xingye",@"bank_circle_zx",@"bank_circle_gd", @"bank_circle_jiaotong"];

    _banktitArr = @[@"招商银行",@"平安银行", @"浦发银行", @"兴业银行",@"中信银行",@"光大银行",@"交通银行"];
    _bankstyleArr = @[@"推荐",@"热门",@"秒批",@"热门",@"推荐",@"高额",@"秒批"];
    self.view.backgroundColor = WYCGlobalBg;
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    
    layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 5);
    layout.footerReferenceSize = CGSizeMake(self.view.frame.size.width, 5);
    
    //该方法也可以设置itemSize
    layout.itemSize =CGSizeMake(ScreenWidth/3-10, 126);
    //    layout.minimumLineSpacing = 10;
    //    layout.minimumInteritemSpacing =10;
    
    UICollectionView * mainCollectionView= [[UICollectionView alloc] initWithFrame:CGRectMake(5, NavHeight, ScreenWidth-10, ScreenHeight-200) collectionViewLayout:layout];
    [self.view addSubview:mainCollectionView];
    mainCollectionView.backgroundColor = WYCGlobalBg;
    //3.注册collectionViewCell
    //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [mainCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
    
    //注册headerView  此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致  均为reusableView
    [mainCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];
    
    //4.设置代理
    mainCollectionView.delegate = self;
    mainCollectionView.dataSource = self;
    
    UIButton * cellbutton = [[UIButton alloc] init];
    cellbutton.frame = CGRectMake(0, ScreenHeight-100, ScreenWidth-0, 50);
    cellbutton.titleLabel.font = [UIFont systemFontOfSize:WyzFont];
    [cellbutton setTitleColor:wycMain forState:UIControlStateNormal];
    cellbutton.contentHorizontalAlignment = UIControlContentVerticalAlignmentCenter;
    [cellbutton addTarget:self action:@selector(loadBank) forControlEvents:UIControlEventTouchUpInside];
    cellbutton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:cellbutton];
    
    UIImageView  *imageClock = [[UIImageView alloc]init];
    imageClock.frame =CGRectMake(ScreenWidth/2-65, 10, 30, 30);
    imageClock.image = [UIImage imageNamed:@"clock"];
    [cellbutton addSubview:imageClock];
    
    UILabel  *clockLb = [[UILabel alloc]init];
    clockLb.frame =CGRectMake(ScreenWidth/2-50, 10,130, 30);
    clockLb.textColor = [UIColor blackColor];
    clockLb.textAlignment = NSTextAlignmentCenter;
    clockLb.text = @"审卡进度查询";
    clockLb.font = [UIFont systemFontOfSize:15];
    [cellbutton addSubview:clockLb];
    
    
    
}
-(void)loadBank
{
    WYCmyCardCotroller  *loadBank = [[WYCmyCardCotroller alloc]init];
    [self.navigationController pushViewController:loadBank animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//Nav字体颜色+ 背景
- (void)setupNav {
    self.navigationItem.title = @"办卡";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [self.navigationController.navigationBar setBarTintColor:wycMain];
}
//设置分区数（必须实现）
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

//设置每个分区的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _banktitArr.count;
}

//设置返回每个item的属性必须实现）
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    UIImageView  *bankBg = [[UIImageView alloc]initWithFrame:CGRectMake(cell.width/2-25, 15, 50, 50)];
    bankBg.image =[UIImage imageNamed:[_bankimgArr objectAtIndex:indexPath.row]];
    [cell.contentView addSubview:bankBg];
    
    UIView  *line  = [[UIView alloc]initWithFrame:CGRectMake(5, bankBg.frame.size.height+bankBg.frame.origin.y+10, ScreenWidth/3-20, 1)];
    line.backgroundColor = WYCGlobalBg;
    [cell.contentView addSubview:line];
    _bankLb = [[UILabel alloc]initWithFrame:CGRectMake(0, bankBg.frame.size.height+bankBg.frame.origin.y+15, ScreenWidth/3-10, 30 )];
    _bankLb.text = [_banktitArr objectAtIndex:indexPath.row];
    _bankLb.textColor = [UIColor grayColor];
    _bankLb.textAlignment =NSTextAlignmentCenter;
    _bankLb.font = [UIFont systemFontOfSize:13];
    [cell.contentView addSubview:_bankLb];
    
    
    UILabel  *style = [[UILabel alloc]initWithFrame:CGRectMake(cell.width-40, 0, 40, 20 )];
    style.text = [_bankstyleArr objectAtIndex:indexPath.row];
    style.textColor = [UIColor whiteColor];
    style.backgroundColor = [UIColor redColor];
    style.textAlignment =NSTextAlignmentCenter;
    style.font = [UIFont systemFontOfSize:13];
    [cell.contentView addSubview:style];
    return cell;
}



-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
        NSString *rowString = [self.banktitArr objectAtIndex:[indexPath row]];
        WYCbankViewController  *bankView = [[WYCbankViewController alloc]init];
        bankView.bankTitle = rowString;
        [self.navigationController pushViewController:bankView animated:YES];
  
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.view.backgroundColor = WYCGlobalBg;
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    UIView * NavView = [[UIView alloc] init];
    NavView.frame = CGRectMake(0, 0, ScreenWidth, NavHeight);
    NavView.backgroundColor = WYCMain;
    [self.view addSubview:NavView];
    
    
    
    CALayer *bottomLineLayer = [[CALayer alloc] init];
    bottomLineLayer.frame = CGRectMake(0, NavView.bounds.size.height - 0.5, NavView.bounds.size.width, 0.5);
    bottomLineLayer.backgroundColor = WYCRGBColor(191, 191, 196).CGColor;
    [NavView.layer addSublayer:bottomLineLayer];
    
    //返回按钮
    UIButton *  fanhuibutton = [[UIButton alloc] init];
    [fanhuibutton setImage:[UIImage imageNamed:@"Nav_back"] forState:UIControlStateNormal];
    [fanhuibutton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    fanhuibutton.frame = CGRectMake(30 * px, 30, 66 * px , 66 * px);
    [NavView addSubview:fanhuibutton];
    
    
    UILabel * NavRigsterLabel = [[UILabel alloc] init];
    NavRigsterLabel.frame = CGRectMake(0, titleY, NavView.width, 68 * px);
    NavRigsterLabel.textColor = [UIColor whiteColor];
    NavRigsterLabel.font = [UIFont boldSystemFontOfSize:BigFont];
    NavRigsterLabel.textAlignment = NSTextAlignmentCenter;
    NavRigsterLabel.text = @"信用卡申请";
    [NavView addSubview:NavRigsterLabel];
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end
